package com.uwlaser.service.dto;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 获取产品唯一编码结果
 */
@Data
public class GetRecipeInfoResult {

    @ApiModelProperty("工序编号")
    private String operationCode;

    @ApiModelProperty("工序名称")
    private String operationName;

    @ApiModelProperty("产品类型")
    private String productType;

    @ApiModelProperty("产品型号")
    private String productCode;

    @ApiModelProperty("产品名称")
    private String productName;

    @ApiModelProperty("程序号")
    private String programNo;

    @ApiModelProperty("参数列表")
    private List<Param> params;

    @ApiModelProperty("工步列表")
    private List<Step> steps;

    /**
     * 添加工艺参数
     * @param paramCode
     * @param paramName
     * @param paramLower
     * @param paramUpper
     * @param paramUnit
     * @param standard
     * @param isNecessary
     */
    public void addParam(String paramCode, String paramName, BigDecimal paramLower, BigDecimal paramUpper, String paramUnit, String standard, String isNecessary){
        if(this.params == null){
            this.params = new ArrayList<>();
        }
        this.params.add(new Param(
                paramCode,
                paramName,
                paramLower,
                paramUpper,
                paramUnit,
                standard,
                isNecessary
        ));
    }

    /**
     * 添加工步
     * @param stepNo
     * @param stepCode
     * @param stepName
     * @param stepType
     * @param stepInstructions
     * @param materialCode
     * @param materialName
     * @param isCheck
     */
    public void addStep(Integer stepNo, String stepCode, String stepName, String stepType, String stepInstructions, String materialCode, String materialName, String isCheck){
        addStep(stepNo, stepCode, stepName, stepType, stepInstructions, materialCode, materialName, isCheck, null , null , null);
    }

    public void addStep(Integer stepNo, String stepCode, String stepName, String stepType, String stepInstructions, String materialCode, String materialName, String isCheck, String program, String sleeve, String tool){
        if(this.steps == null){
            this.steps = new ArrayList<>();
        }
        this.steps.add(new Step(stepNo, stepCode, stepName, stepType, stepInstructions, materialCode, materialName, isCheck, program, sleeve, tool));
    }

    /**
     * 工艺参数
     */
    @Data
    public class Param {

        @ApiModelProperty("参数编号")
        private String paramCode;

        @ApiModelProperty("参数名称")
        private String paramName;

        @ApiModelProperty("下限")
        private BigDecimal paramLower;

        @ApiModelProperty("上限")
        private BigDecimal paramUpper;

        @ApiModelProperty("单位")
        private String paramUnit;

        @ApiModelProperty("标准值")
        private String standard;

        @ApiModelProperty("是否必须上传")
        private String isNecessary;

        public Param(String paramCode, String paramName, BigDecimal paramLower, BigDecimal paramUpper, String paramUnit, String standard, String isNecessary) {
            this.paramCode = paramCode;
            this.paramName = paramName;
            this.paramLower = paramLower.setScale(2, BigDecimal.ROUND_HALF_UP);
            this.paramUpper = paramUpper.setScale(2, BigDecimal.ROUND_HALF_UP);
            this.paramUnit = paramUnit;
            this.standard = standard;
            this.isNecessary = isNecessary;
        }
    }

    /**
     * 工艺工步
     */
    @Data
    public class Step {

        @ApiModelProperty("工步序号")
        private Integer stepNo;

        @ApiModelProperty("工步编号")
        private String stepCode;

        @ApiModelProperty("工步名称")
        private String stepName;

        @ApiModelProperty("工步类型")
        private String stepType;

        @ApiModelProperty("工步指示")
        private String stepInstructions;

        @ApiModelProperty("物料编码")
        private String materialCode;

        @ApiModelProperty("物料名称")
        private String materialName;

        @ApiModelProperty("是否校验")
        private String isCheck;

        @ApiModelProperty("程序号")
        private String program;

        @ApiModelProperty("套筒号")
        private String sleeve;

        @ApiModelProperty("拧紧枪号")
        private String tool;

        public Step(Integer stepNo, String stepCode, String stepName, String stepType, String stepInstructions, String materialCode, String materialName, String isCheck) {
            this.stepNo = stepNo;
            this.stepCode = stepCode;
            this.stepName = stepName;
            this.stepType = stepType;
            this.stepInstructions = stepInstructions;
            this.materialCode = materialCode;
            this.materialName = materialName;
            this.isCheck = isCheck;
        }

        public Step(Integer stepNo, String stepCode, String stepName, String stepType, String stepInstructions, String materialCode, String materialName, String isCheck, String program, String sleeve, String tool) {
            this.stepNo = stepNo;
            this.stepCode = stepCode;
            this.stepName = stepName;
            this.stepType = stepType;
            this.stepInstructions = stepInstructions;
            this.materialCode = materialCode;
            this.materialName = materialName;
            this.isCheck = isCheck;
            this.program = program;
            this.sleeve = sleeve;
            this.tool = tool;
        }
    }
}
